package org.csu.myPetStore.service;

import org.csu.myPetStore.domain.Account;
import org.csu.myPetStore.domain.Category;
import org.csu.myPetStore.domain.Item;
import org.csu.myPetStore.domain.Product;
import org.csu.myPetStore.persistence.AccountDAO;
import org.csu.myPetStore.persistence.CategoryDAO;
import org.csu.myPetStore.persistence.ItemDAO;
import org.csu.myPetStore.persistence.ProductDAO;
import org.csu.myPetStore.persistence.impl.CategoryDAOImpl;
import org.csu.myPetStore.persistence.impl.ItemDAOImpl;
import org.csu.myPetStore.persistence.impl.ProductDAOImpl;

import java.util.List;

public class CatalogService {

  //业务逻辑连接层，让用户使用该部分而不管其如何实现

  private CategoryDAO categoryDAO;
  private ProductDAO productDAO;
  private ItemDAO itemDAO;

  public CatalogService(){
    categoryDAO = new CategoryDAOImpl();
    productDAO = new ProductDAOImpl();
    itemDAO = new ItemDAOImpl();
  }

  public List<Category> getCategoryList() {
    return categoryDAO.getCategoryList();
  }

  public Category getCategory(String categoryId) {
    return categoryDAO.getCategory(categoryId);
  }

  public Product getProduct(String productId) {
    return productDAO.getProduct(productId);
  }

  public List<Product> getProductListByCategory(String categoryId) {
    return productDAO.getProductListByCategory(categoryId);
  }

  // TODO enable using more than one keyword
  public List<Product> searchProductList(String keyword) {
    return productDAO.searchProductList("%" + keyword.toLowerCase() + "%");
  }


  public List<Item> getItemListByProduct(String productId) {
    return itemDAO.getItemListByProduct(productId);
  }

  public Item getItem(String itemId) {
    return itemDAO.getItem(itemId);
  }

  public boolean isItemInStock(String itemId) {
    return itemDAO.getInventoryQuantity(itemId) > 0;
  }

}